package sudroid.oauth;

import java.net.HttpURLConnection;
import sudroid.LogUtils;
import sudroid.java.util.Arrays;
import sudroid.net2.HttpClient;
import sudroid.net2.HttpException;
import sudroid.net2.PostParameter;
import sudroid.net2.Response;
import sudroid.security.Base64;

public class BasicOAuthClient extends HttpClient
{
  private static final long serialVersionUID = -912190657247482116L;
  private String accessTokenURL = "http://api.t.sina.com.cn/oauth/access_token";
  private String authenticationURL = "http://api.t.sina.com.cn/oauth/authenticate";
  private String authorizationURL = "http://api.t.sina.com.cn/oauth/authorize";
  private String basic;
  private OAuth oauth = null;
  private OAuthToken oauthToken = null;
  private String password;
  private String requestTokenURL = "http://api.t.sina.com.cn/oauth/request_token";
  private String token = null;
  private String userId;

  public BasicOAuthClient()
  {
    setOAuthConsumer(null, null);
    this.basic = null;
  }

  public BasicOAuthClient(String paramString1, String paramString2)
  {
    this();
    this.userId = paramString1;
    this.password = paramString2;
    encodeBasicAuthenticationString();
  }

  private void encodeBasicAuthenticationString()
  {
    if ((this.userId != null) && (this.password != null))
    {
      StringBuilder localStringBuilder1 = new StringBuilder("Basic ");
      String str1 = String.valueOf(this.userId);
      StringBuilder localStringBuilder2 = new StringBuilder(str1).append(":");
      String str2 = this.password;
      char[] arrayOfChar = Base64.encode(str2.getBytes());
      String str3 = new String(arrayOfChar);
      String str4 = str3;
      this.basic = str4;
      this.oauth = null;
    }
  }

  public String getAccessTokenURL()
  {
    return this.accessTokenURL;
  }

  public String getAuthenticationURL()
  {
    return this.authenticationURL;
  }

  public String getAuthorizationURL()
  {
    return this.authorizationURL;
  }

  public AccessToken getOAuthAccessToken(String paramString1, String paramString2)
    throws HttpException
  {
    int i;
    try
    {
      BasicOAuthClient.1 local1 = new BasicOAuthClient.1(this, paramString1, paramString2);
      this.oauthToken = local1;
      String str = this.accessTokenURL;
      PostParameter[] arrayOfPostParameter = new PostParameter[0];
      Response localResponse = httpRequest(str, arrayOfPostParameter);
      AccessToken localAccessToken = new AccessToken(localResponse);
      this.oauthToken = localAccessToken;
      return (AccessToken)this.oauthToken;
    }
    catch (HttpException localHttpException)
    {
      i = localHttpException.getStatusCode();
    }
    throw new HttpException("The user has not given access to the account.", localHttpException, i);
  }

  public AccessToken getOAuthAccessToken(String paramString1, String paramString2, String paramString3)
    throws HttpException
  {
    int i;
    try
    {
      BasicOAuthClient.2 local2 = new BasicOAuthClient.2(this, paramString1, paramString2);
      this.oauthToken = local2;
      String str = this.accessTokenURL;
      PostParameter[] arrayOfPostParameter = new PostParameter[1];
      PostParameter localPostParameter = new PostParameter("oauth_verifier", paramString3);
      arrayOfPostParameter[0] = localPostParameter;
      Response localResponse = httpRequest(str, arrayOfPostParameter);
      AccessToken localAccessToken = new AccessToken(localResponse);
      this.oauthToken = localAccessToken;
      return (AccessToken)this.oauthToken;
    }
    catch (HttpException localHttpException)
    {
      i = localHttpException.getStatusCode();
    }
    throw new HttpException("The user has not given access to the account.", localHttpException, i);
  }

  public AccessToken getOAuthAccessToken(RequestToken paramRequestToken)
    throws HttpException
  {
    int i;
    try
    {
      this.oauthToken = paramRequestToken;
      String str = this.accessTokenURL;
      PostParameter[] arrayOfPostParameter = new PostParameter[0];
      Response localResponse = httpRequest(str, arrayOfPostParameter);
      AccessToken localAccessToken = new AccessToken(localResponse);
      this.oauthToken = localAccessToken;
      return (AccessToken)this.oauthToken;
    }
    catch (HttpException localHttpException)
    {
      i = localHttpException.getStatusCode();
    }
    throw new HttpException("The user has not given access to the account.", localHttpException, i);
  }

  public AccessToken getOAuthAccessToken(RequestToken paramRequestToken, String paramString)
    throws HttpException
  {
    int i;
    try
    {
      this.oauthToken = paramRequestToken;
      String str = this.accessTokenURL;
      PostParameter[] arrayOfPostParameter = new PostParameter[1];
      PostParameter localPostParameter = new PostParameter("oauth_verifier", paramString);
      arrayOfPostParameter[0] = localPostParameter;
      Response localResponse = httpRequest(str, arrayOfPostParameter);
      AccessToken localAccessToken = new AccessToken(localResponse);
      this.oauthToken = localAccessToken;
      return (AccessToken)this.oauthToken;
    }
    catch (HttpException localHttpException)
    {
      i = localHttpException.getStatusCode();
    }
    throw new HttpException("The user has not given access to the account.", localHttpException, i);
  }

  public RequestToken getOAuthRequestToken()
    throws HttpException
  {
    String str = this.requestTokenURL;
    PostParameter[] arrayOfPostParameter = new PostParameter[0];
    Response localResponse = httpRequest(str, arrayOfPostParameter);
    RequestToken localRequestToken = new RequestToken(localResponse, this);
    this.oauthToken = localRequestToken;
    return (RequestToken)this.oauthToken;
  }

  public RequestToken getOauthRequestToken(String paramString)
    throws HttpException
  {
    String str = this.requestTokenURL;
    PostParameter[] arrayOfPostParameter = new PostParameter[1];
    PostParameter localPostParameter = new PostParameter("oauth_callback", paramString);
    arrayOfPostParameter[0] = localPostParameter;
    Response localResponse = httpRequest(str, arrayOfPostParameter);
    RequestToken localRequestToken = new RequestToken(localResponse, this);
    this.oauthToken = localRequestToken;
    return (RequestToken)this.oauthToken;
  }

  public String getPassword()
  {
    return this.password;
  }

  public String getRequestTokenURL()
  {
    return this.requestTokenURL;
  }

  public String getUserId()
  {
    return this.userId;
  }

  protected Response httpRequest(String paramString, PostParameter[] paramArrayOfPostParameter)
    throws HttpException
  {
    PostParameter[] arrayOfPostParameter;
    if (paramArrayOfPostParameter != null)
    {
      int i = paramArrayOfPostParameter.length + 1;
      arrayOfPostParameter = (PostParameter[])Arrays.copyOf(paramArrayOfPostParameter, i);
      int j = paramArrayOfPostParameter.length;
      PostParameter localPostParameter1 = new PostParameter("source", "");
      arrayOfPostParameter[j] = localPostParameter1;
    }
    while (true)
    {
      return httpRequest(paramString, null, arrayOfPostParameter);
      arrayOfPostParameter = new PostParameter[1];
      PostParameter localPostParameter2 = new PostParameter("source", "");
      arrayOfPostParameter[0] = localPostParameter2;
    }
  }

  public boolean isAuthenticationEnabled()
  {
    if ((this.basic == null) && (this.oauth == null));
    for (int i = 0; ; i = 1)
      return i;
  }

  public void setAccessTokenURL(String paramString)
  {
    this.accessTokenURL = paramString;
  }

  public void setAuthorizationURL(String paramString)
  {
    this.authorizationURL = paramString;
  }

  protected void setHeaders(String paramString, PostParameter[] paramArrayOfPostParameter, HttpURLConnection paramHttpURLConnection)
  {
    super.setHeaders(paramString, paramArrayOfPostParameter, paramHttpURLConnection);
    OAuth localOAuth;
    String str1;
    OAuthToken localOAuthToken;
    if (this.oauth != null)
    {
      localOAuth = this.oauth;
      if (paramArrayOfPostParameter != null)
      {
        str1 = "POST";
        localOAuthToken = this.oauthToken;
      }
    }
    for (String str2 = localOAuth.generateAuthorizationHeader(str1, paramString, paramArrayOfPostParameter, localOAuthToken); ; str2 = this.basic)
    {
      paramHttpURLConnection.addRequestProperty("Authorization", str2);
      LogUtils.d("Authorization: " + str2);
      return;
      str1 = "GET";
      break;
      if (this.basic == null)
        break label99;
    }
    label99: throw new IllegalStateException("Neither user ID/password combination nor OAuth consumer key/secret combination supplied");
  }

  public void setOAuthAccessToken(AccessToken paramAccessToken)
  {
    this.oauthToken = paramAccessToken;
  }

  public void setOAuthConsumer(String paramString1, String paramString2)
  {
    if ((paramString1 != null) && (paramString2 != null) && (paramString1.length() != 0) && (paramString2.length() != 0))
    {
      OAuth localOAuth = new OAuth(paramString1, paramString2);
      this.oauth = localOAuth;
    }
  }

  protected void setPassword(String paramString)
  {
    this.password = paramString;
    encodeBasicAuthenticationString();
  }

  public void setRequestTokenURL(String paramString)
  {
    this.requestTokenURL = paramString;
  }

  public RequestToken setToken(String paramString1, String paramString2)
  {
    this.token = paramString1;
    RequestToken localRequestToken = new RequestToken(paramString1, paramString2);
    this.oauthToken = localRequestToken;
    return (RequestToken)this.oauthToken;
  }

  protected void setUserId(String paramString)
  {
    this.userId = paramString;
    encodeBasicAuthenticationString();
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.oauth.BasicOAuthClient
 * JD-Core Version:    0.6.0
 */